package com.kaisa.activity.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.kaisa.activity.R;
import com.kaisa.activity.bean.SearchDetails;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2015/12/13.
 * sortfragment适配器
 */
public class SearchAdapter extends AppBaseAdapter<SearchDetails>{

    public SearchAdapter(List<SearchDetails> list, Context context) {
        super(list, context);
        inflater = LayoutInflater.from(context);
    }


    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_list_search,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        //映射数据
        SearchDetails searchDetails = list.get(position);
        x.image().bind(holder.img, searchDetails.getImageUrl());
        holder.lineName.setText(searchDetails.getLineName());
        holder.subTitle.setText(searchDetails.getSubTitle());
        holder.score.setText(searchDetails.getScore());
        holder.joinpeoplenum.setText(searchDetails.getJoinpeoplenum());
        holder.presalePrice.setText(searchDetails.getPresalePrice());
        if (searchDetails.getRetailPrice()!=null) {
            holder.retailPrice.setText(searchDetails.getRetailPrice());
            holder.retailPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        }
        return convertView;
    }

    public static class ViewHolder extends BaseViewHolder{
        @ViewInject(R.id.iv_search_img)
        private ImageView img;
        @ViewInject(R.id.tv_search_lineName)
        private TextView lineName;
        @ViewInject(R.id.tv_search_subTitle)
        private TextView subTitle;
        @ViewInject(R.id.tv_search_score)
        private TextView score;
        @ViewInject(R.id.tv_search_joinpeoplenum)
        private TextView joinpeoplenum;
        @ViewInject(R.id.tv_search_presalePrice)
        private TextView presalePrice;
        @ViewInject(R.id.tv_search_retailPrice)
        private TextView retailPrice;


        public ViewHolder(View convertView) {
            super(convertView);
            x.view().inject(this,convertView);
        }
    }
}
